package com.example.servicemap.remote;


import com.example.internalcommon.constant.AmapConfigConstants;
import com.example.internalcommon.dto.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @Author lyra
 * @Date 2023/4/11 15:14
 **/
@Service
public class MapDicDistrictClient {

    @Value("${amap.key}")
    private String amapkey;

    @Autowired
    private RestTemplate restTemplate;

    /**
     * 16.请求高德地图地区字典
     * @param keywords
     * @return
     */
    public String DicDistrict(String keywords){

        // 拼装请求的url
        StringBuilder url = new StringBuilder();
        url.append(AmapConfigConstants.DISTRICT_URL);
        url.append("?");
        url.append("keywords="+keywords);
        url.append("&");
        url.append("subdistrict=3");
        url.append("&");
        url.append("key="+amapkey);

        ResponseEntity<String> forEntity = restTemplate.getForEntity(url.toString(), String.class);


        return forEntity.getBody();
    }

}
